import routerList from "./routerconfig";
import {Suspense} from "react"
import {Route,Routes,Navigate,BrowserRouter} from "react-router-dom"
// routes保证路由匹配的正确性和唯一性
let RouterView = ()=>{
    let renderRouter = (routerList)=> {
        return routerList.map((item,index)=>{
            return item.path ? <Route key={index} path={item.path} element={<item.component></item.component>}>
                    {
                        item.children && renderRouter(item.children)
                    }
            </Route>:<Route key={index} path={item.from} element={<Navigate to={item.to}></Navigate>}></Route>
        })
    }
    return <BrowserRouter>
                <Suspense fallback={<div>...加载中</div>}>
                    <Routes>
                        {/* <Route></Route>
                        <Route></Route>
                        <Route></Route> */}
                        {
                            renderRouter(routerList)
                        }
                    </Routes>
                </Suspense>
            </BrowserRouter>
}
export default RouterView